--- permalink: /python/offline layout: user-guide page_type: u-guide description: How to use Plotly offline inside IPython notebooks with Plotly Offline name: Plotly Offline for IPython Notebooks language: python has_thumbnail: false thumbnail: /images/static-image --- {% raw %}
Plotly Offline brings interactive Plotly graphs to the offline IPython Notebook environment.
Instead of saving the graphs to a server, your data and graphs will remain inside your IPython notebook. When your ready to share, you can just publish them to the Plotly Cloud or to your company's internal Plotly Enterprise.
To get started with Plotly Offline, start a trial or contact sales@plot.ly to learn about licensing and receive a URL to download the package.
! pip install plotly --upgrade
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
print __version__ # requires version >= 1.7.5
download_plotlyjs('your_licensed_plotly_offline_url') # Contact sales@plot.ly to receive a valid URL
init_notebook_mode() # run at the start of every ipython notebook
iplot([{"x": [1, 2, 3], "y": [3, 1, 6]}])
from plotly.graph_objs import *
import numpy as np
iplot([Box(y = np.random.randn(50), showlegend=False) for i in range(45)])
x = np.random.randn(2000)
y = np.random.randn(2000)
iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')),
Scatter(x=x, y=y, mode='markers', marker=Marker(color='white', size=3, opacity=0.3))])
import pandas as pd
df = pd.read_csv('https://plot.ly/~etpinard/191.csv')
df.head(1)
iplot({
'data': [
Scatter(x=df[continent+'_Life Expentancy [in years]'],
y=df[continent+'_Gross Domestic Product per Capita [in USD of the year 2000]'],
text=df[continent+'_text'],
marker=Marker(size=df[continent+'_marker.size'], sizemode='area', sizeref=131868,),
mode='markers',
name=continent) for continent in ['Africa', 'Americas', 'Asia', 'Europe', 'Oceania']
],
'layout': Layout(xaxis=XAxis(title='Life Expectancy'), yaxis=YAxis(title='GDP per Capita', type='log'))
})
df = pd.read_csv('https://gist.githubusercontent.com/chriddyp/694f77aa92073a4da4c5/raw/a96a5e87e17b8edec0b8197c79e9da87c8cde2ac/topographic_data.csv', header=None)
iplot({'data': [Surface(z=[df[col] for col in df.columns])], 'layout': {'height': 1000}})
import pandas as pd
df_airports = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
df_airports.head()
df_flight_paths = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_aa_flight_paths.csv')
df_flight_paths.head()
airports = [ dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = df_airports['long'],
lat = df_airports['lat'],
hoverinfo = 'text',
text = df_airports['airport'],
mode = 'markers',
marker = dict(
size=2,
color='rgb(255, 0, 0)',
line = dict(
width=3,
color='rgba(68, 68, 68, 0)'
)
))]
flight_paths = []
for i in range( len( df_flight_paths ) ):
flight_paths.append(
dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = [ df_flight_paths['start_lon'][i], df_flight_paths['end_lon'][i] ],
lat = [ df_flight_paths['start_lat'][i], df_flight_paths['end_lat'][i] ],
mode = 'lines',
line = dict(
width = 1,
color = 'red',
),
opacity = float(df_flight_paths['cnt'][i])/float(df_flight_paths['cnt'].max()),
)
)
layout = dict(
title = 'Feb. 2011 American Airline flight paths<br>(Hover for airport names)',
showlegend = False,
height = 900,
geo = dict(
scope='north america',
projection=dict( type='azimuthal equal area' ),
showland = True,
landcolor = 'rgb(243, 243, 243)',
countrycolor = 'rgb(204, 204, 204)',
),
)
fig = dict( data=flight_paths + airports, layout=layout )
iplot(fig)
import plotly.plotly as py
fig = py.get_figure('https://plot.ly/~jackp/8715', raw=True)
iplot(fig)